package com.learn.thread;

/**
 * 线程常用方法：
 * 1、yield() 切换到同等优先级或者优先级更高的线程
 * 2、join()  当前调用join的线程会被阻塞
 * 3、isAlive() 线程是否存活,返回boolean
 *
 */
public class TreadMethoud {
    public static void main(String[] args) {
        Threadm myThread = new Threadm();
        myThread.setName("mythread");
        myThread.start();
        for (int i =0;i<100;i++){
            if (i%2 != 0){
                System.out.println(Thread.currentThread().getName()+":"+i);
            }
            if (i == 95){
                try {
                    myThread.join();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
        System.out.println(myThread.isAlive());
    }
}

class Threadm extends Thread{
    @Override
    public void run() {
        for (int i =0;i<100;i++){
            if (i%2 == 0){
                System.out.println(Thread.currentThread().getName()+":"+i);
            }

        }
    }
}
